package org.utnrepasa.net.util;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Representa una partida o juego de UTN REPASA.
 * 
 * @author Parisi Germán
 * @version 1.3
 */
public class Game implements Serializable {
	private static final long serialVersionUID = 1001;
	/**
	 * Estado de la partida.
	 */
	public enum STATE {

		STARTED, FINALIZED, WAITING
	}

	/**
	 * Es el id de la partida o juego.
	 */
	private int id;

	/**
	 * Jugador creador.
	 */
	protected Player creator;

	/**
	 * Cantidad de rondas del juego.
	 */
	private int rounds;

	/**
	 * Cantidad de preguntas por ronda.
	 */
	private int questionsPerRound;

	/**
	 * Es la ronda actual del juego. La primer ronda es la número 1 y así.
	 * Este atributo tiene sentido solo cuando el estado es STARTED, de otra
	 * manera este atributo vale 0.
	 */
	private int currentRound;

	/**
	 * Son las materias en que se basan las preguntas.
	 */
	private ArrayList<Course> courses;

	/**
	 * Es el estado en el que está el juego.
	 */
	private STATE state;

	public Game(int id, Player creator, int rounds, int questionsPerRound) {
		this(id, creator, rounds, questionsPerRound, STATE.WAITING);
	}

	public Game(int id, int rounds, int questionsPerRound) {
		this(id, null, rounds, questionsPerRound);
	}

	public Game(int id, Player creator, int rounds, int questionsPerRound,
			STATE state) {
		this.id = id;
		this.creator = creator;
		this.rounds = rounds;
		this.questionsPerRound = questionsPerRound;
		this.state = state;
		this.courses = new ArrayList<Course>();
	}

	public void addMateria(Course course) {
		this.courses.add(course);
	}

	public int getId() {
		return this.id;
	}

	public Player getCreator() {
		return creator;
	}

	public int getRounds() {
		return rounds;
	}

	public int getQuestionsPerRound() {
		return questionsPerRound;
	}

	public int getCurrentRound() {
		return currentRound;
	}

	public STATE getState() {
		return state;
	}

	public ArrayList<Course> getCourses() {
		return this.courses;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setCreator(Player player) {
		this.creator = player;
	}

	public void setRounds(int rounds) {
		this.rounds = rounds;
	}

	public void setQuestionsPerRound(int questionsPerRound) {
		this.questionsPerRound = questionsPerRound;
	}

	public void setCurrentRound(int currentRound) {
		this.currentRound = currentRound;
	}

	public void setState(STATE state) {
		this.state = state;
	}

	public void setCourses(ArrayList<Course> courses) {
		this.courses = courses;
	}

	public void setStateString(String state) {
		if (state.equals("J")) {
			this.state = STATE.STARTED;
		} else if (state.equals("E")) {
			this.state = STATE.WAITING;
		} else if (state.equals("F")) {
			this.state = STATE.FINALIZED;
		}
	}

	@Override
	public String toString() {
		return String.valueOf(id) + " " + creator.getName();
	}
}
